package com.lxy.u4day04.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lxy.u4day04.dao.UserMapper;
import com.lxy.u4day04.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@Transactional
public class UserServiceImpl implements UserService{

    @Autowired(required = false)
    private UserMapper userMapper;

    @Override
    public List<User> findUser() {
        return userMapper.findUser();
    }

    @Override
    public Map<String, Object> getUser(Integer pageNum) {
        Map<String, Object> map = null;
        try {
            PageHelper.startPage(pageNum,1);
            List<User> user = userMapper.findUser();
            PageInfo pageInfo = new PageInfo(user);
            map = new HashMap<>();
            map.put("code",200);
            map.put("msg","分页查询成功");
            map.put("data",user);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("code",500);
            map.put("msg","分页查询失败");
        }
        return map;
    }
}
